<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>思途CMS{$coreVersion}</title>
    {template 'stourtravel/public/public_min_js'}
    {php echo Common::getScript("uploadify/jquery.uploadify.min.js,listimageup.js,jquery.validate.js"); }
    {php echo Common::getCss('uploadify.css','js/uploadify/'); }
    {php echo Common::getCss('base.css,style.css,destination_dialog_basicinfo.css'); }
</head>
<body>
   <div class="s-main">
       <div class="main-body">
           <div class="nav">
               <div class="w-set-tit bom-arrow">
                   <span data-rel="seo" class="on"><s></s>基本信息</span>
               </div>
               <div class="clear-both"></div>
           </div>
           <div class="nav-list">
               <form id="frm">
               <div class="item-one" id="item_seo">
                   <table>
                       <tr><td class="tit">名称：</td><td><input type="text" name="name" id="field_name" class="set-text-xh text_250" value="{$info['name']}"/></td></tr>
                       <tr><td class="tit">类型：</td>
                           <td>
                               <select name="type" id="field_type">
                                   <option value="2" {if $info['type']==2}selected="selected"{/if}>机场</option>
                                   <option value="0" {if !empty($info['type']) && $info['type']==0}selected="selected"{/if}>区域</option>
                                   <option value="1" {if $info['type']==1}selected="selected"{/if}>城市</option>
                               </select>
                           </td>
                       </tr>
                       <tr><td class="tit">英文：</td><td><input type="text" name="english" id="field_english" class="set-text-xh text_250" value="{$info['english']}"/></td></tr>
                       <tr id="item_code"><td class="tit">三字码：</td><td><input type="text" name="code" id="field_code" class="set-text-xh text_250" value="{$info['code']}"/></td></tr>
                   </table>
               </div>

               </form>
           </div>
       </div>
       <div class="save-con">
           <a href="javascript:;" class="confirm-btn">确定</a>
       </div>
   </div>
<script>
    var pid="{$pid}";
    var id = "{$info['id']}";
    $(function() {
        //类型改变
         $("#field_type").change(function(){
              var type = $(this).val();
              if(type==2)
              {
                  $("#item_code").show();
              }
              else
              {
                  $("#item_code").hide();
              }
         });
         $("#field_type").trigger('change');

        //确认提交
        $(document).on('click','.confirm-btn',function(){
             $("#frm").submit();
        })



        //添加三字码验证函数
        jQuery.validator.addMethod("code3", function(value, element) {
            var v = /^[a-zA-Z]{3}$/;
            return this.optional(element) || (v.test(value));
        }, "三字码不正确");

        //添加英文验证函数
        jQuery.validator.addMethod("english", function(value, element) {
            var v = /^[a-zA-Z\s]{2,}$/;
            return this.optional(element) || (v.test(value));
        }, "格式不正确");


        $("#frm").validate({
            rules: {
                name:
                {
                    required:true
                },
                english:
                {
                    required:true,
                    english:true
                },
                code:{
                    required: {
                        depends: function (element) {
                            return $("#sel_type").val() == 2 ? true : false;
                        }
                    },
                    code3:true
                }
            },
            messages: {
                name: {
                    required:"名称不能为空"
                },
                english:{
                    required:"英文不能为空",
                    english:"格式不正确"
                },
                code:
                {
                    required:"三字码不能为空",
                    code3:"格式错误"
                }
            },
            submitHandler:function(form){

                var data={};
                data.name=$("#field_name").val();
                data.type=$("#field_type").val();
                data.english=$("#field_english").val();
                data.code=$("#field_code").val();
                data.id=id;
                ST.Util.responseDialog(data,true);
                return false;
            }

        });


    })
</script>

</body>
</html>
